function isFullscreen() {
  return !!(
    document.fullscreenElement ||
    document.webkitFullscreenElement ||
    document.mozFullScreenElement ||
    document.msFullscreenElement
  );
}

function fullScreen(dom = document?.documentElement) {
  const isTrue = !!dom;
  if (isTrue && dom?.requestFullscreen) {
    dom.requestFullscreen();
  } else if (isTrue && dom?.mozRequestFullScreen) {
    // 火狐
    dom.mozRequestFullScreen();
  } else if (isTrue && dom?.webkitRequestFullScreen) {
    // 谷歌等
    dom.webkitRequestFullScreen();
  } else if (isTrue && dom?.msRequestFullscreen) {
    // IE
    dom.msRequestFullscreen();
  } else {
    dom.requestFullscreen();
  }
}

function exitFullScreen() {
  if (document.exitFullscreen) {
    document.exitFullscreen();
    return;
  } else if (document.webkitExitFullscreen) {
    /* Safari */
    document.webkitExitFullscreen();
    return;
  } else if (document.msExitFullscreen) {
    /* IE11 */
    document.msExitFullscreen();
    return;
  }
  // let cfs =
  //     dom.cancelFullScreen ||
  //     dom.webkitCancelFullScreen ||
  //     dom.mozCancelFullScreen ||
  //     dom.exitFullScreen,
  //   wscript;

  // if (typeof cfs != 'undefined' && cfs) {
  //   cfs.call(dom);
  //   return;
  // }
  let wscript;
  if (typeof window.ActiveXObject != 'undefined') {
    wscript = new ActiveXObject('WScript.Shell');
    if (wscript != null) {
      wscript.SendKeys('{F11}');
    }
  }
}

function toggleFull(dom = document.body) {
  const isFullsc = isFullscreen();
  isFullsc ? exitFullScreen() : fullScreen(dom);
  return !isFullsc;
}

export { isFullscreen, fullScreen, exitFullScreen, toggleFull };
